package com.tedu.parkinglot.carPort.service.impl;

import com.tedu.parkinglot.carPort.mapper.CarportMapper;
import com.tedu.parkinglot.carPort.pojo.dto.CarportQuery;
import com.tedu.parkinglot.carPort.pojo.dto.CarportSaveParam;
import com.tedu.parkinglot.carPort.pojo.entity.CarportAdmin;
import com.tedu.parkinglot.carPort.pojo.vo.CarportVO;
import com.tedu.parkinglot.carPort.service.CarportService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Collections;
import java.util.List;

@Slf4j
@Service
public class CarportServiceImpl implements CarportService {

    @Autowired
    private CarportMapper carportMapper;
    @Override
    public List<CarportVO> select(CarportQuery carportQuery) {
        log.info("查询车位信息：{}", carportQuery);
        List<CarportVO> list = carportMapper.select(carportQuery);
        log.debug("查询结果：{}", list);
        return list;
    }

    @Override
    public void save(CarportSaveParam carportSaveParam) {
        log.info("保存车位信息：{}", carportSaveParam);
        CarportAdmin carportAdmin = new CarportAdmin();
        BeanUtils.copyProperties(carportSaveParam, carportAdmin);
        if (carportAdmin.getId() == null){
            carportMapper.insert(carportAdmin);
        }else {
            carportMapper.update(carportAdmin);
        }
    }

    @Override
    public void delete( Long id) {
        log.info("删除车位信息：{}", id);
        carportMapper.delete(id);
    }
}
